<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
    <title>Virus Bacteria Interaction Prediction</title>
    <link rel="stylesheet" type="text/css" href="lib/css/bootstrap.min.css"/>
    <link rel="stylesheet" type="text/css" href="lib/css/jquery-ui.min.css"/>
    <link rel="stylesheet" type="text/css" href="lib/jqwidgets/styles/jqx.base.css" />
    <link rel="stylesheet" type="text/css" href="css/styles.css"/>
    <link rel="stylesheet" type="text/css" href="lib/css/custom_new.css">
    
    <script type="text/javascript" src="lib/js/d3.js"></script>
    <script type="text/javascript" src="lib/js/jquery-1.11.2.min.js"></script>
    <script type="text/javascript" src="lib/js/jquery-ui.min.js"></script>
    <script type="text/javascript" src="lib/js/bootstrap.min.js"></script>
    <script type="text/javascript" src="lib/js/math.min.js"></script>
    <script type="text/javascript" src="lib/jqwidgets/jqx-all.js"></script>
</head>


<body>
	
<div id="tooltip1" class="hidden"><p><span id="value"></div>

<div id="container-id-1" style="width: 1670px; height: 1000px; clear: both;">
	<div class="sidebar_wrapper" style="float: left; width: 300px; height: 1000px; overflow: hidden; display: block; border-right: 1px solid grey;">
		<div class="title_section">
			<img class="title_image" src="logo.jpg" alt="" style="width: 290px; margin-left: 2px; margin-top: 5px;">
		</div>
		
		<div class="reorder_section" style="margin: 1px; margin-top: 10px; padding:2px; font-size: 11px; border: 0.5px solid grey;">
			<div id='jqxWidget'><label>Select the Virus for visualization: </label><div id="listbox"></div></div>
			
			<div class="opacity_slider_container" style="margin-top: 5px;">
				<div ><label for="topAmount"># of top Hosts: </label><input type="text" value="25" id="topAmount" readonly style="border:0; font-weight:bold; width: 50px;"></div>
				<div id="topSlider" style="width: 290px;"></div>
			</div>
			<div class="opacity_slider_container" style="margin-top: 5px;">
				<div ><label for="cutoffAmount">Max distance &lt;= </label><input type="text" value="1" id="cutoffAmount" readonly style="border:0; font-weight:bold; width: 50px;"></div>
				<div id="cutoffSlider" style="width: 290px;"></div>
			</div>
			<div class="btn-group gene_search_button" data-toggle="buttons" style="margin-top: 10px;">
				<div><button id="okBtn" class="sidebar_text btn btn-primary submit_gene_button" type="button" disabled="true" onclick="updateData()" style="float: left; padding-top: 6px; padding-bottom: 6px;">OK</button></div>
			</div>
		</div>
	</div>
	<div id="vizcontainer" style="float: left; width: 1000px; height: 800px; overflow: auto; ">
		<svg id="heatCanvas"></svg> 
	</div>
	<div style="float: left;margin-left: 20px; margin-top: 50px; ">
		<div><b>Consensus Information</b></div>
		<div id="consensusSuperkingdom"></div>
		<div id="consensusPhylum"></div>
		<div id="consensusClass"></div>
		<div id="consensusOrder"></div>
		<div id="consensusFamily"></div>
		<div id="consensusGenus"></div>
		<div id="consensusSpecies"></div>
	</div>
</div>


<footer id="footer_div" class="footer navbar-fixed-bottom">
    <div class="row"><div class="col-xs-12 footer_section"><p class="text-muted">Copyright (C) 2016 Yang Lu &lt;<a href="mailto:ylu465@usc.edu">ylu465@usc.edu</a>&gt; @ Computational and Molecular Biology, Department of Biological Science, University of Southern California, LA, CA 90089, USA </p></div></div>
</footer>

<script type="text/javascript">
	var margin = {top: 200, right: 10, bottom: 10, left: 200};
   var colors = ['#91003F','#9B1A53','#A63467','#B14F7C','#BB6990','#C684A4','#D19EB9','#DBB9CD','#E6D3E1','#F1EEF6','#FFFFFF'];
   
   var virusNameIdxMap = new Object(), hostNameIdxMap = new Object();   
   var topHostNum = 50, cutoff = 1;
   var checkedVirusIdxArr = [], checkedVirusArr = [], hostArr = [], edgeData =[];
   var virusNameArr = ["NC_019843.3.fasta", "NC_004297.0.fasta", "NC_001802.1.fasta", "NC_001722.1.fasta", "NC_002023.0.fasta", "NC_004718.3.fasta", "NC_006998.1.fasta", "AC_000017.1.fasta", "NC_003977.2.fasta", "NC_012532.1.fasta", "NC_045512.2.fasta", "NC_038312.1.fasta", "NC_002728.1.fasta", "NC_006273.2.fasta", "NC_001803.1.fasta", "NC_009333.1.fasta", "NC_001348.1.fasta", "NC_001798.2.fasta", "NC_001538.1.fasta", "NC_001355.1.fasta", "NC_001436.1.fasta", "NC_005219.1.fasta", "NC_001430.1.fasta", "NC_001906.3.fasta", "NC_038311.1.fasta", "NC_010415.1.fasta", "NC_001731.1.fasta", "JX276378.1.fasta", "NC_006307.0.fasta", "NC_001806.2.fasta", "NC_001796.2.fasta", "NC_001611.1.fasta", "NC_003443.1.fasta", "NC_001664.4.fasta", "NC_002549.1.fasta", "NC_004102.1.fasta", "NC_002204.0.fasta", "NC_007605.1.fasta", "NC_004162.2.fasta"];
var hostNameArr = ["NC_019843.3.fasta", "NC_004297.0.fasta", "NC_001802.1.fasta", "NC_001722.1.fasta", "NC_002023.0.fasta", "NC_004718.3.fasta", "NC_006998.1.fasta", "AC_000017.1.fasta", "NC_003977.2.fasta", "NC_012532.1.fasta", "NC_045512.2.fasta", "NC_038312.1.fasta", "NC_002728.1.fasta", "NC_006273.2.fasta", "NC_001803.1.fasta", "NC_009333.1.fasta", "NC_001348.1.fasta", "NC_001798.2.fasta", "NC_001538.1.fasta", "NC_001355.1.fasta", "NC_001436.1.fasta", "NC_005219.1.fasta", "NC_001430.1.fasta", "NC_001906.3.fasta", "NC_038311.1.fasta", "NC_010415.1.fasta", "NC_001731.1.fasta", "JX276378.1.fasta", "NC_006307.0.fasta", "NC_001806.2.fasta", "NC_001796.2.fasta", "NC_001611.1.fasta", "NC_003443.1.fasta", "NC_001664.4.fasta", "NC_002549.1.fasta", "NC_004102.1.fasta", "NC_002204.0.fasta", "NC_007605.1.fasta", "NC_004162.2.fasta"];
var virusHostMat = [[-3.33067e-16,0.455385,0.477711,0.493373,0.486252,0.378629,0.441478,0.463828,0.491007,0.462071,0.379492,0.491362,0.465762,0.472582,0.456867,0.458546,0.47384,0.479016,0.470112,0.482221,0.491787,0.483846,0.477736,0.470628,0.491887,0.465593,0.480434,0.475062,0.469808,0.471436,0.461846,0.435905,0.469702,0.487861,0.479491,0.486202,0.463917,0.469519,0.468991],
[0.455385,-1.11022e-16,0.477174,0.485581,0.477127,0.479278,0.471361,0.48959,0.495774,0.483891,0.454074,0.499244,0.474281,0.484358,0.483968,0.492682,0.493446,0.484174,0.473567,0.503734,0.497906,0.490972,0.487378,0.48276,0.488223,0.489477,0.469736,0.488887,0.472715,0.49282,0.4556,0.467478,0.46065,0.485436,0.470873,0.491762,0.471569,0.469728,0.492452],
[0.477711,0.477174,-2.22045e-16,0.426101,0.505212,0.448932,0.463423,0.48658,0.499658,0.466527,0.457864,0.487085,0.48639,0.474657,0.473251,0.478078,0.484414,0.468152,0.49553,0.468139,0.479837,0.490887,0.47893,0.470402,0.492243,0.482908,0.490597,0.516205,0.464449,0.478849,0.471007,0.463952,0.486335,0.463511,0.472504,0.478821,0.454328,0.471054,0.475454],
[0.493373,0.485581,0.426101,0,0.48973,0.469893,0.467274,0.473581,0.48176,0.484413,0.467086,0.472357,0.489214,0.456697,0.482651,0.451628,0.454846,0.46614,0.484901,0.480312,0.4822,0.502299,0.49724,0.497229,0.477076,0.4863,0.46359,0.500722,0.472479,0.477107,0.470948,0.473363,0.450105,0.469031,0.483018,0.473411,0.460924,0.466317,0.468583],
[0.486252,0.477127,0.505212,0.48973,-1.11022e-16,0.476553,0.493441,0.508577,0.50302,0.480396,0.498866,0.490244,0.481847,0.509776,0.489414,0.498358,0.491575,0.491599,0.490285,0.478591,0.507216,0.484943,0.490693,0.494388,0.512002,0.490857,0.503172,0.485598,0.474448,0.494259,0.488003,0.483843,0.464557,0.504922,0.482448,0.508088,0.460191,0.516483,0.494226],
[0.378629,0.479278,0.448932,0.469893,0.476553,5.55112e-17,0.434084,0.460555,0.480702,0.460096,0.309376,0.480646,0.439308,0.444005,0.465589,0.458905,0.489926,0.46986,0.490893,0.489602,0.489646,0.486882,0.455558,0.444624,0.45615,0.455218,0.456557,0.467702,0.453691,0.462593,0.459311,0.423832,0.455304,0.466604,0.45565,0.47474,0.431395,0.449792,0.460413],
[0.441478,0.471361,0.463423,0.467274,0.493441,0.434084,1.66533e-16,0.445545,0.480145,0.472145,0.446725,0.483886,0.467374,0.407827,0.474767,0.417816,0.436803,0.448845,0.476828,0.481334,0.479431,0.490683,0.479969,0.471874,0.480766,0.486621,0.473504,0.491081,0.468671,0.44745,0.479862,0.103265,0.455809,0.428231,0.476777,0.471352,0.458393,0.441629,0.455567],
[0.463828,0.48959,0.48658,0.473581,0.508577,0.460555,0.445545,3.33067e-16,0.49104,0.478086,0.465619,0.48887,0.471288,0.324883,0.475763,0.343458,0.411605,0.353196,0.486654,0.466111,0.449644,0.502221,0.486943,0.478807,0.47753,0.494053,0.3753,0.501762,0.479639,0.364202,0.480615,0.439591,0.467255,0.386462,0.470052,0.420541,0.485706,0.352469,0.445061],
[0.491007,0.495774,0.499658,0.48176,0.50302,0.480702,0.480145,0.49104,1.66533e-16,0.484131,0.484691,0.496247,0.475708,0.475784,0.493541,0.484926,0.490549,0.481926,0.480932,0.480456,0.489759,0.480545,0.481242,0.485264,0.49991,0.48724,0.486163,0.485978,0.484292,0.488029,0.490225,0.482992,0.482111,0.477515,0.484452,0.490454,0.486111,0.492157,0.48666],
[0.462071,0.483891,0.466527,0.484413,0.480396,0.460096,0.472145,0.478086,0.484131,5.55112e-17,0.451174,0.495264,0.47881,0.471478,0.476957,0.467661,0.473734,0.485289,0.481201,0.489646,0.485138,0.482652,0.511692,0.474419,0.497388,0.500896,0.47623,0.504525,0.48167,0.483773,0.473624,0.471041,0.474476,0.478151,0.479214,0.471377,0.477978,0.481686,0.462431],
[0.379492,0.454074,0.457864,0.467086,0.498866,0.309376,0.446725,0.465619,0.484691,0.451174,0,0.49452,0.455693,0.450221,0.457187,0.470991,0.469854,0.469606,0.468488,0.473308,0.493897,0.48677,0.469101,0.460317,0.463718,0.467293,0.465287,0.457929,0.465967,0.464593,0.456468,0.437908,0.462329,0.46889,0.461469,0.470626,0.449716,0.451935,0.450371],
[0.491362,0.499244,0.487085,0.472357,0.490244,0.480646,0.483886,0.48887,0.496247,0.495264,0.49452,5.55112e-17,0.496116,0.493239,0.488488,0.47715,0.478341,0.48447,0.500034,0.487508,0.480294,0.475585,0.44859,0.477672,0.465723,0.451377,0.491927,0.46424,0.467158,0.479403,0.481485,0.480816,0.498826,0.478912,0.485498,0.493515,0.475221,0.484144,0.504488],
[0.465762,0.474281,0.48639,0.489214,0.481847,0.439308,0.467374,0.471288,0.475708,0.47881,0.455693,0.496116,1.66533e-16,0.455561,0.458832,0.473775,0.497473,0.47609,0.462589,0.489836,0.475804,0.491222,0.485667,0.404357,0.460202,0.476165,0.469949,0.467825,0.450575,0.471548,0.444862,0.45604,0.434328,0.476208,0.465503,0.483892,0.467819,0.479981,0.475775],
[0.472582,0.484358,0.474657,0.456697,0.509776,0.444005,0.407827,0.324883,0.475784,0.471478,0.450221,0.493239,0.455561,2.22045e-16,0.480562,0.330684,0.42442,0.275634,0.478284,0.481619,0.474741,0.502745,0.497849,0.461391,0.470571,0.48836,0.328866,0.487043,0.47589,0.296126,0.476997,0.406056,0.468843,0.377364,0.462116,0.42694,0.487743,0.327402,0.439748],
[0.456867,0.483968,0.473251,0.482651,0.489414,0.465589,0.474767,0.475763,0.493541,0.476957,0.457187,0.488488,0.458832,0.480562,-3.33067e-16,0.488901,0.465459,0.484391,0.485174,0.50304,0.487543,0.500594,0.490112,0.45649,0.4942,0.479562,0.494276,0.476934,0.500311,0.484625,0.462824,0.468123,0.461946,0.461609,0.48147,0.480267,0.476352,0.489547,0.476469],
[0.458546,0.492682,0.478078,0.451628,0.498358,0.458905,0.417816,0.343458,0.484926,0.467661,0.470991,0.47715,0.473775,0.330684,0.488901,3.33067e-16,0.389982,0.339041,0.491136,0.477359,0.450703,0.499486,0.480123,0.47202,0.476791,0.481594,0.388533,0.47242,0.474445,0.335319,0.479137,0.408694,0.475135,0.385194,0.473227,0.441464,0.493379,0.322823,0.448756],
[0.47384,0.493446,0.484414,0.454846,0.491575,0.489926,0.436803,0.411605,0.490549,0.473734,0.469854,0.478341,0.497473,0.42442,0.465459,0.389982,-1.11022e-16,0.411142,0.469731,0.451881,0.471007,0.518402,0.488051,0.486794,0.482538,0.500426,0.473686,0.502377,0.460451,0.400375,0.48387,0.432016,0.473383,0.384898,0.488196,0.4516,0.491523,0.412777,0.471044],
[0.479016,0.484174,0.468152,0.46614,0.491599,0.46986,0.448845,0.353196,0.481926,0.485289,0.469606,0.48447,0.47609,0.275634,0.484391,0.339041,0.411142,-1.11022e-16,0.484533,0.484976,0.471444,0.505534,0.499506,0.470886,0.471104,0.494549,0.323737,0.492804,0.487246,0.130135,0.473963,0.451456,0.468974,0.406329,0.473598,0.423772,0.489941,0.300861,0.452898],
[0.470112,0.473567,0.49553,0.484901,0.490285,0.490893,0.476828,0.486654,0.480932,0.481201,0.468488,0.500034,0.462589,0.478284,0.485174,0.491136,0.469731,0.484533,5.55112e-17,0.468938,0.47636,0.469321,0.50055,0.480386,0.479272,0.505302,0.492541,0.488384,0.487758,0.484799,0.489334,0.472127,0.473593,0.492312,0.469031,0.503656,0.485114,0.483018,0.491058],
[0.482221,0.503734,0.468139,0.480312,0.478591,0.489602,0.481334,0.466111,0.480456,0.489646,0.473308,0.487508,0.489836,0.481619,0.50304,0.477359,0.451881,0.484976,0.468938,-1.11022e-16,0.492995,0.491201,0.503654,0.488952,0.476132,0.487454,0.513059,0.496715,0.460446,0.489811,0.489019,0.465603,0.495566,0.473842,0.483747,0.481359,0.467817,0.469806,0.491726],
[0.491787,0.497906,0.479837,0.4822,0.507216,0.489646,0.479431,0.449644,0.489759,0.485138,0.493897,0.480294,0.475804,0.474741,0.487543,0.450703,0.471007,0.471444,0.47636,0.492995,-1.11022e-16,0.493847,0.494432,0.472659,0.47975,0.489902,0.463673,0.501214,0.479305,0.479645,0.493386,0.472416,0.481168,0.474782,0.478677,0.479814,0.488115,0.465992,0.49601],
[0.483846,0.490972,0.490887,0.502299,0.484943,0.486882,0.490683,0.502221,0.480545,0.482652,0.48677,0.475585,0.491222,0.502745,0.500594,0.499486,0.518402,0.505534,0.469321,0.491201,0.493847,1.66533e-16,0.485152,0.474844,0.475091,0.494974,0.502784,0.477957,0.477431,0.499793,0.499475,0.500237,0.489133,0.51788,0.470652,0.493132,0.498529,0.498447,0.476185],
[0.477736,0.487378,0.47893,0.49724,0.490693,0.455558,0.479969,0.486943,0.481242,0.511692,0.469101,0.44859,0.485667,0.497849,0.490112,0.480123,0.488051,0.499506,0.50055,0.503654,0.494432,0.485152,2.22045e-16,0.479935,0.460793,0.44947,0.499943,0.443268,0.472848,0.492935,0.477285,0.478123,0.49371,0.500412,0.498176,0.510407,0.481745,0.482652,0.491576],
[0.470628,0.48276,0.470402,0.497229,0.494388,0.444624,0.471874,0.478807,0.485264,0.474419,0.460317,0.477672,0.404357,0.461391,0.45649,0.47202,0.486794,0.470886,0.480386,0.488952,0.472659,0.474844,0.479935,0,0.469693,0.471938,0.487696,0.479343,0.480763,0.471355,0.441983,0.468879,0.457013,0.466531,0.45524,0.472691,0.470226,0.485428,0.471766],
[0.491887,0.488223,0.492243,0.477076,0.512002,0.45615,0.480766,0.47753,0.49991,0.497388,0.463718,0.465723,0.460202,0.470571,0.4942,0.476791,0.482538,0.471104,0.479272,0.476132,0.47975,0.475091,0.460793,0.469693,-2.22045e-16,0.444799,0.479951,0.451795,0.468773,0.477857,0.490361,0.47673,0.482963,0.47006,0.473003,0.486285,0.497436,0.475739,0.475732],
[0.465593,0.489477,0.482908,0.4863,0.490857,0.455218,0.486621,0.494053,0.48724,0.500896,0.467293,0.451377,0.476165,0.48836,0.479562,0.481594,0.500426,0.494549,0.505302,0.487454,0.489902,0.494974,0.44947,0.471938,0.444799,5.55112e-17,0.482259,0.455158,0.464044,0.493908,0.486088,0.481234,0.496907,0.499717,0.497204,0.496413,0.476836,0.474766,0.491947],
[0.480434,0.469736,0.490597,0.46359,0.503172,0.456557,0.473504,0.3753,0.486163,0.47623,0.465287,0.491927,0.469949,0.328866,0.494276,0.388533,0.473686,0.323737,0.492541,0.513059,0.463673,0.502784,0.499943,0.487696,0.479951,0.482259,4.44089e-16,0.489287,0.476783,0.362498,0.490702,0.472793,0.470895,0.445396,0.47116,0.435325,0.494506,0.370285,0.474988],
[0.475062,0.488887,0.516205,0.500722,0.485598,0.467702,0.491081,0.501762,0.485978,0.504525,0.457929,0.46424,0.467825,0.487043,0.476934,0.47242,0.502377,0.492804,0.488384,0.496715,0.501214,0.477957,0.443268,0.479343,0.451795,0.455158,0.489287,-3.33067e-16,0.496741,0.484596,0.492838,0.478986,0.497041,0.5064,0.489832,0.500077,0.496348,0.488961,0.488493],
[0.469808,0.472715,0.464449,0.472479,0.474448,0.453691,0.468671,0.479639,0.484292,0.48167,0.465967,0.467158,0.450575,0.47589,0.500311,0.474445,0.460451,0.487246,0.487758,0.460446,0.479305,0.477431,0.472848,0.480763,0.468773,0.464044,0.476783,0.496741,-3.33067e-16,0.487295,0.46492,0.457762,0.479149,0.462578,0.469527,0.482645,0.4309,0.482093,0.474914],
[0.471436,0.49282,0.478849,0.477107,0.494259,0.462593,0.44745,0.364202,0.488029,0.483773,0.464593,0.479403,0.471548,0.296126,0.484625,0.335319,0.400375,0.130135,0.484799,0.489811,0.479645,0.499793,0.492935,0.471355,0.477857,0.493908,0.362498,0.484596,0.487295,-4.44089e-16,0.481587,0.447888,0.475985,0.403483,0.480575,0.429956,0.489544,0.307506,0.449913],
[0.461846,0.4556,0.471007,0.470948,0.488003,0.459311,0.479862,0.480615,0.490225,0.473624,0.456468,0.481485,0.444862,0.476997,0.462824,0.479137,0.48387,0.473963,0.489334,0.489019,0.493386,0.499475,0.477285,0.441983,0.490361,0.486088,0.490702,0.492838,0.46492,0.481587,5.55112e-17,0.470367,0.444629,0.47689,0.486354,0.489069,0.454552,0.489912,0.479517],
[0.435905,0.467478,0.463952,0.473363,0.483843,0.423832,0.103265,0.439591,0.482992,0.471041,0.437908,0.480816,0.45604,0.406056,0.468123,0.408694,0.432016,0.451456,0.472127,0.465603,0.472416,0.500237,0.478123,0.468879,0.47673,0.481234,0.472793,0.478986,0.457762,0.447888,0.470367,4.996e-16,0.445709,0.421859,0.472997,0.474093,0.445415,0.439493,0.454602],
[0.469702,0.46065,0.486335,0.450105,0.464557,0.455304,0.455809,0.467255,0.482111,0.474476,0.462329,0.498826,0.434328,0.468843,0.461946,0.475135,0.473383,0.468974,0.473593,0.495566,0.481168,0.489133,0.49371,0.457013,0.482963,0.496907,0.470895,0.497041,0.479149,0.475985,0.444629,0.445709,5.55112e-17,0.469929,0.452955,0.478748,0.479946,0.485036,0.495648],
[0.487861,0.485436,0.463511,0.469031,0.504922,0.466604,0.428231,0.386462,0.477515,0.478151,0.46889,0.478912,0.476208,0.377364,0.461609,0.385194,0.384898,0.406329,0.492312,0.473842,0.474782,0.51788,0.500412,0.466531,0.47006,0.499717,0.445396,0.5064,0.462578,0.403483,0.47689,0.421859,0.469929,-3.33067e-16,0.482028,0.442477,0.483574,0.418941,0.462753],
[0.479491,0.470873,0.472504,0.483018,0.482448,0.45565,0.476777,0.470052,0.484452,0.479214,0.461469,0.485498,0.465503,0.462116,0.48147,0.473227,0.488196,0.473598,0.469031,0.483747,0.478677,0.470652,0.498176,0.45524,0.473003,0.497204,0.47116,0.489832,0.469527,0.480575,0.486354,0.472997,0.452955,0.482028,0,0.474281,0.474729,0.486545,0.47084],
[0.486202,0.491762,0.478821,0.473411,0.508088,0.47474,0.471352,0.420541,0.490454,0.471377,0.470626,0.493515,0.483892,0.42694,0.480267,0.441464,0.4516,0.423772,0.503656,0.481359,0.479814,0.493132,0.510407,0.472691,0.486285,0.496413,0.435325,0.500077,0.482645,0.429956,0.489069,0.474093,0.478748,0.442477,0.474281,-1.11022e-16,0.487381,0.459514,0.469694],
[0.463917,0.471569,0.454328,0.460924,0.460191,0.431395,0.458393,0.485706,0.486111,0.477978,0.449716,0.475221,0.467819,0.487743,0.476352,0.493379,0.491523,0.489941,0.485114,0.467817,0.488115,0.498529,0.481745,0.470226,0.497436,0.476836,0.494506,0.496348,0.4309,0.489544,0.454552,0.445415,0.479946,0.483574,0.474729,0.487381,-1.11022e-16,0.495354,0.494762],
[0.469519,0.469728,0.471054,0.466317,0.516483,0.449792,0.441629,0.352469,0.492157,0.481686,0.451935,0.484144,0.479981,0.327402,0.489547,0.322823,0.412777,0.300861,0.483018,0.469806,0.465992,0.498447,0.482652,0.485428,0.475739,0.474766,0.370285,0.488961,0.482093,0.307506,0.489912,0.439493,0.485036,0.418941,0.486545,0.459514,0.495354,-3.33067e-16,0.465895],
[0.468991,0.492452,0.475454,0.468583,0.494226,0.460413,0.455567,0.445061,0.48666,0.462431,0.450371,0.504488,0.475775,0.439748,0.476469,0.448756,0.471044,0.452898,0.491058,0.491726,0.49601,0.476185,0.491576,0.471766,0.475732,0.491947,0.474988,0.488493,0.474914,0.449913,0.479517,0.454602,0.495648,0.462753,0.47084,0.469694,0.494762,0.465895,1.66533e-16]];
var superkingdomArr = ["unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown"];
var phylumArr = ["unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown"];
var classArr = ["unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown"];
var orderArr = ["unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown"];
var familyArr = ["unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown"];
var genusArr = ["unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown"];
var speciesArr = ["unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown"];
var organismArr = ["unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown"];

   for(var hostIdx=0; hostIdx<hostNameArr.length; hostIdx++) hostNameIdxMap[hostNameArr[hostIdx]] = hostIdx;
   for(var virusIdx=0; virusIdx<virusNameArr.length; virusIdx++) virusNameIdxMap[virusNameArr[virusIdx]] = virusIdx;
   console.log("phageToHost finish loading!");
   
   topHostNum = Math.min(25, hostNameArr.length);
   
   $(function() { $( "#topSlider" ).slider({ value:25, min: 1, max: 100, step: 1, slide: function( event, ui ) { $( "#topAmount" ).val( ui.value ); topHostNum = Math.min(ui.value, hostNameArr.length);  } }); }); 
   $(function() { $( "#cutoffSlider" ).slider({ value:1, min: 0, max: 1, step: 0.01, slide: function( event, ui ) { $( "#cutoffAmount" ).val( ui.value ); cutoff = ui.value; } }); });
   
   
   $("#listbox").jqxListBox({width: 290, height: 300, source: virusNameArr, checkboxes: true, filterable: true});
		$("#listbox").on('checkChange', function (event) {
			var items = $("#listbox").jqxListBox('getCheckedItems');
			checkedVirusIdxArr = []; checkedVirusArr = [];
			$.each(items, function (index) { checkedVirusIdxArr.push(this.index); checkedVirusArr.push(this.label); });
			
			if(checkedVirusIdxArr.length > 0) $("#okBtn").prop('disabled', false);
			else $("#okBtn").prop('disabled', true);
   });
   
   var host2organism = [], host2superkingdom = [], host2phylum = [], host2class = [], 
		host2order = [], host2family = [], host2genus = [], host2species = [];
   
   for(var t=0; t<hostNameArr.length; t++){
   		host2organism[hostNameArr[t]] = organismArr[t];
   		host2superkingdom[hostNameArr[t]] = superkingdomArr[t];
   		host2phylum[hostNameArr[t]] = phylumArr[t];
   		host2class[hostNameArr[t]] = classArr[t];
   		host2order[hostNameArr[t]] = orderArr[t];
   		host2family[hostNameArr[t]] = familyArr[t];
   		host2genus[hostNameArr[t]] = genusArr[t];
   		host2species[hostNameArr[t]] = speciesArr[t];
	}
	console.log("hostTaxonomy finish loading!");
	
	var minDist = 1, maxDist = 0, gap=0;
	for(var rowIdx=0; rowIdx<virusHostMat.length; rowIdx++) 
	{
		for(var colIdx=0; colIdx<virusHostMat[0].length; colIdx++)
		{
			if(virusHostMat[rowIdx][colIdx]<minDist) minDist = virusHostMat[rowIdx][colIdx];
			if(virusHostMat[rowIdx][colIdx]>maxDist) maxDist = virusHostMat[rowIdx][colIdx];
		}
	}
	minDist = Math.max(0,minDist-0.1); maxDist = Math.min(1,maxDist+0.1); gap = maxDist-minDist;
	var colorScale = d3.scale.quantile().domain([minDist,maxDist]).range(colors);

	function updateData() {
		topHostNum = Math.min(topHostNum, hostNameArr.length);

		var combinedArr = new Array(virusHostMat[checkedVirusIdxArr[0]].length).fill(0);
		for(var rowIdx=0; rowIdx<checkedVirusIdxArr.length; rowIdx++) {
			for(var colIdx=0; colIdx<virusHostMat[checkedVirusIdxArr[rowIdx]].length; colIdx++) {
				combinedArr[colIdx] += virusHostMat[checkedVirusIdxArr[rowIdx]][colIdx];
			}
		}
		var tmpArr = combinedArr.slice(); 
		var thres = tmpArr.sort().slice(topHostNum-1,topHostNum);

		indiceArr = [];
		for(var colIdx=0; colIdx<combinedArr.length; colIdx++) {
			if(indiceArr.length >= topHostNum) break;
			if(combinedArr[colIdx] <= thres) { indiceArr.push({"idx":colIdx, "dist":combinedArr[colIdx] }); }
		}
		
		hostArr = []; edgeData =[];
		for(var colIdx=0; colIdx<indiceArr.length; colIdx++) {
			var realColIdx = indiceArr[colIdx].idx;
			hostArr.push(hostNameArr[realColIdx]);
			
			for(var rowIdx=0; rowIdx<checkedVirusIdxArr.length; rowIdx++) { edgeData.push({"row":rowIdx, "col":hostArr.length-1, 
				"value":virusHostMat[checkedVirusIdxArr[rowIdx]][realColIdx]<=cutoff?virusHostMat[checkedVirusIdxArr[rowIdx]][realColIdx]:1}); }
		}
		
		pathArr = [];
		for(var colIdx=0; colIdx<hostArr.length; colIdx++) { pathArr.push([host2superkingdom[hostArr[colIdx]],host2phylum[hostArr[colIdx]],host2class[hostArr[colIdx]],host2order[hostArr[colIdx]],host2family[hostArr[colIdx]],host2genus[hostArr[colIdx]],host2species[hostArr[colIdx]]]); }
		//rootNode = 	convertToHierarchy(pathArr);
		//consensusArr = getConsensusTaxonomy(rootNode); 
		
		$("#consensusSuperkingdom").text("Superkingdom: "+getConsensusItem(pathArr,0));
		$("#consensusPhylum").text("Phylum: "+getConsensusItem(pathArr,1));
		$("#consensusClass").text("Class: "+getConsensusItem(pathArr,2));
		$("#consensusOrder").text("Order: "+getConsensusItem(pathArr,3));
		$("#consensusFamily").text("Family: "+getConsensusItem(pathArr,4));
		$("#consensusGenus").text("Genus: "+getConsensusItem(pathArr,5));
		$("#consensusSpecies").text("Species: "+getConsensusItem(pathArr,6));
		
		var cellSize = 25, legendElementWidth = cellSize*2, 
			width = Math.max(hostArr.length*cellSize, 1000 ), height = Math.max(checkedVirusIdxArr.length*cellSize, 700 );
		
		console.log();
		
		d3.selectAll(".canvasSvg").remove(); 
		var svg = d3.select("#heatCanvas").style("float", "left").attr("width", width).attr("height", height)
			.append("g").attr('class', "canvasSvg").attr("transform", "translate(" + margin.left + "," + margin.top + ")");
			
		var rowLabels = svg.append("g").selectAll(".rowLabelg").data(checkedVirusArr).enter().append("text")
			.text(function (d) { return d; }).attr("x", 0).attr("y", function (d, i) { return i * cellSize; })
      		.style("text-anchor", "end").attr("transform", "translate(-6," + cellSize / 1.5 + ")")
      		.attr("class", function (d,i) { return "rowLabel mono r"+i;} ) ;
      		
      	var colLabels = svg.append("g").selectAll(".colLabelg").data(hostArr).enter().append("text")
      		.text(function (d) { return d; }).attr("x", 0).attr("y", function (d, i) { return i * cellSize; })
      		.style("text-anchor", "left").attr("transform", "translate("+cellSize/2 + ",-6) rotate (-90)")
      		.attr("class",  function (d,i) { return "colLabel mono c"+i;} );
      	
      	var heatMap = svg.append("g").attr("class","g3").selectAll(".cellg").data(edgeData).enter().append("rect")
			.attr("x", function(d) { return d.col * cellSize; }).attr("y", function(d) { return d.row * cellSize; })
        	.attr("class", function(d){return "cell cell-border cr"+(d.row)+" cc"+(d.col);})
        	.attr("width", cellSize).attr("height", cellSize).style("fill", function(d) { return colorScale(d.value); })
			.on("mouseover", function(d){
				d3.selectAll(".cell").filter(function(el) {return d.row == el.row || d.col == el.col; }).classed("cell-hover",true);
				d3.selectAll(".rowLabel").classed("text-highlight",function(r,ri){ return ri==d.row;});
				d3.selectAll(".colLabel").classed("text-highlight",function(c,ci){ return ci==d.col;});
				
				d3.select("#tooltip1").style("left", (d3.event.pageX+10) + "px").style("top", (d3.event.pageY-10) + "px")
					.html("Host Information: "+
						"<br> Superkingdom: "+ host2superkingdom[hostArr[d.col]] +
						"<br> Phylum: "+ host2phylum[hostArr[d.col]] +
						"<br> Class: "+ host2class[hostArr[d.col]] +
						"<br> Order: "+ host2order[hostArr[d.col]] +
						"<br> Family: "+ host2family[hostArr[d.col]] +
						"<br> Genus: "+ host2genus[hostArr[d.col]] +
						"<br> Species: "+ host2species[hostArr[d.col]] +
						"<br> Organism: "+ host2organism[hostArr[d.col]] +
						"<br> distance:"+d.value);  
                d3.select("#tooltip1").classed("hidden", false);
			})
			.on("mouseout", function(d){
				d3.selectAll(".cell").filter(function(el) {return d.row == el.row || d.col == el.col; }).classed("cell-hover",false);
				d3.selectAll(".rowLabel").classed("text-highlight",false);
				d3.selectAll(".colLabel").classed("text-highlight",false);
				d3.select("#tooltip1").classed("hidden", true);
			});
      		
      	var legend = svg.selectAll(".legend").data([minDist,minDist+0.1*gap,minDist+0.2*gap,minDist+0.3*gap,minDist+0.4*gap,minDist+0.5*gap,minDist+0.6*gap,minDist+0.7*gap,minDist+0.8*gap,minDist+0.9*gap,maxDist]).enter().append("g").attr("class", "legend");
		legend.append("rect").attr("x", function(d, i) { return legendElementWidth * i-margin.left; }).attr("y", (cellSize*2) - margin.top)
    		.attr("width", legendElementWidth).attr("height", cellSize)
    		.style("fill", function(d, i) { return colors[i]; });
    
    	legend.append("text").text(function(d) { return d3.format(".2f")(d); }).style("text-anchor", "left")
    		.attr("x", function(d, i) { return legendElementWidth * i-margin.left; }).attr("y", (cellSize*4)- margin.top);
	}
	
	function getConsensusItem(pathArr, idx)
	{
		var node = {id:"root", cnt:0, children:{}};
		for (var i = 0; i < pathArr.length; i++) 
		{
			var path = pathArr[i];
			node.cnt ++;
			item = path[idx];
			if (!node.children[item]) node.children[item] = {id:item, cnt:0, children:{}};
			node.children[item].cnt ++;
		}
		
		var arr = Object.keys( node.children ).map(function ( key ) { return node.children[key].cnt; });
		var ratio = 100;
		if(math.sum(arr) > 0) ratio = Math.max.apply(Math,arr)*100/math.sum(arr);
		maxItem = Object.keys(node.children)[arr.indexOf(Math.max.apply(Math,arr))];
		return node.children[maxItem].id+" ("+String(Math.round(ratio * 100) / 100)+"%)";
	}
	
	function convertToHierarchy(pathArr) {
		var rootNode = {id:"root", cnt:0, children:{}};
		for (var i = 0; i < pathArr.length; i++) {
			var path = pathArr[i];
			buildNodeRecursive(rootNode, path, 0);
		}
		return rootNode;
	}
	
	function buildNodeRecursive(node, path, idx) {
		if (idx < path.length) {
			node.cnt ++;
			item = path[idx];			
			if (!node.children[item]) node.children[item] = {id:item, cnt:0, children:{}};
			buildNodeRecursive(node.children[item], path, idx + 1);
		}
	}
	
	function getConsensusTaxonomy(currNode) {
		if(currNode.children && Object.keys(currNode.children).length > 0) {
			var arr = Object.keys( currNode.children ).map(function ( key ) { return currNode.children[key].cnt; });
			//console.log(arr + " : " +arr.length);
			//console.log(arr + " : " +Math.max.apply(Math,arr) +" : " + arr.indexOf(Math.max.apply(Math,arr)));
			//console.log(Math.max.apply(Math,arr) + " / " +math.sum(arr));
			
			var ratio = 100;
			if(math.sum(arr) > 0) ratio = Math.max.apply(Math,arr)*100/math.sum(arr);
			
			maxItem = Object.keys(currNode.children)[arr.indexOf(Math.max.apply(Math,arr))];
			
			returnArr = [currNode.children[maxItem].id+" ("+String(Math.round(ratio * 100) / 100)+"%)"];
			returnArr = returnArr.concat(getConsensusTaxonomy(currNode.children[maxItem]));
			return returnArr;
		}
		return [currNode.id+" (100%)"];
	}
	

</script>

</body>
</html>